<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Commentlist
 *
 * @author ewdt
 */
class Commentlist extends CWidget {

    public $item;

    public function init() {
        $model = new Comment;
        if (isset($_POST['Comment'])) {
            $model->attributes = $_POST['Comment'];
            $model->user_id = Yii::app()->user->id;
            $model->item_id = $this->item->id;
            if ($model->save()) {
                $model->unsetAttributes();
            }
        }
        $this->render('form', array('model' => $model));
    }

    public function run() {
        foreach ($this->item->comments as $comment) {
            $this->render('displaycomments', array('model' => $comment));
        }
    }

}

?>
